# -*- coding:utf-8 -*-

from common.ReadConfig import ReadConfig
from common.HTMLTestRunner import HTMLTestRunner
import common.NewReport as nr


# 最新报告名称
def run_case(all_case):
    """执行所有的用例，并把结果写入测试报告"""

    # 获取执行环境
    env = str(ReadConfig().get_env('env'))

    if env == 'fat':
        nowEnv = 'FAT环境'
    elif env == 'uat':
        nowEnv = 'UAT环境'
    else:
        nowEnv = env + '环境'

    # 执行用例
    fp = open(nr.new_report(), "wb")
    # print(nr.new_report())
    runner = HTMLTestRunner(stream=fp,
                            title="{}接口自动化测试报告".format(nowEnv),
                            description="Hi,all:本次接口自动化用例结果如下:")

    runner.run(all_case)
    fp.close()
    print("测试用例执行完毕，测试报告已生成")